/*
  Copyright © 2010  Vinícius dos Santos Oliveira
  Copyright © 2010  Camilo Costa Campos

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef COLABORATIVECONTROLLER_H
#define COLABORATIVECONTROLLER_H

#include <QGraphicsScene>
#include "widgets/pushbuttonitem.h"
#include "colaborative/manager.h"
#include "colaborative/colaborative_conf.h"
#include "stage.h"
#include "colaborative/interpreter.h"

namespace Touche
{
    class ColaborativeController: public QObject
    {
        Q_OBJECT

        QGraphicsScene *scene;
        PushButtonItem *startButton;
        ColaborativeManager *manager;
        ColaborationWindow *mainDialog;
        Stage *stage;
        Interpreter reader;

        static ColaborativeController *master;

        ColaborativeController(Stage *stage, QGraphicsScene *scene);

    public:
        ~ColaborativeController();

        void colaborateElement(Touche::Element *element);
        void colaborateLink(const QUuid &src, const QUuid &dst);

        void killColaboratedElement(Touche::Element *element);
        void killColaboratedLink(const QUuid &src, const QUuid &dst);

        static ColaborativeController *getInstance(Stage *stage = 0, QGraphicsScene *scene = 0);

    public slots:

        void onStartEditing(const QUuid &uuid);
        void onFinishEditing(const QUuid &uuid);

        void onElement(const QUuid &uuid, const QString &type, const QString &xml, const QString &file); //used when a colaborator added an Element
        void onLink(const QUuid &first, const QUuid &second);

        void lockElement(Element *element);
        void unlockElement(Element *element);

        void onElementKilled(const QUuid &uuid);
        void onLinkKilled(const QUuid &src, const QUuid &sink);

        void start();

    signals:
        void addElement(Touche::Element *element); //used when my user add an Element
        void addLink(QUuid, QUuid);
    };
}

#endif // COLABORATIVECONTROLLER_H
